package com.example.demo2.controller;


import com.example.demo2.entity.Method;
import com.example.demo2.entity.Target;

import com.example.demo2.service.TargetService;
import com.google.gson.Gson;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/target")
//target
public class TargetController {
    @Autowired
    private TargetService targetService;
//要注入对应的接口实现类，首先应该保证容器中有这样的类

    @GetMapping("/target")
    public Object target(@Param("courseTargetId") Integer courseTargetId){

        Target target=targetService.queryTargetById(courseTargetId);

        return target;
    }

    @RequestMapping(value = "/AddTarget")
    @ResponseBody
    public int addtarget(@Param("courseTargetId") Integer courseTargetId,@Param("courseId") Integer courseId,@Param("courseTargetShortname") String courseTargetShortname,@Param("bulumuTarget") Integer bulumuTarget,@Param("courseTargetContent") String courseTargetContent ){

//
//    Target target
//        完成参数的输入 （律晓佳的注释）
        System.out.println(courseTargetShortname+"课程目标简称");
        System.out.println(courseTargetId+"课程目标ID");
        System.out.println(courseId+"课程ID");
        System.out.println(bulumuTarget+"布鲁姆目标");
        System.out.println(courseTargetContent+"课程目标内容");
        return targetService.lv_insertTarget(courseTargetId,courseId,courseTargetShortname,bulumuTarget,courseTargetContent);
    }
//  根据课程目标ID完成数据的删除
    @RequestMapping("/DeleteTarget")
    public int DeleteTarget(@Param("courseTargetId") Integer courseTargetId)
    {
        return targetService.Lv_deleteTargetById(courseTargetId);
    }


//根据课程目标ID完成对应记录的修改
    @RequestMapping("/UpdateTarget")
    public int UpdateTarget(@Param("courseTargetId") Integer courseTargetId,@Param("courseId") Integer courseId,
                             @Param("courseTargetShortname") String courseTargetShortname,@Param("bulumuTarget") Integer bulumuTarget,@Param("courseTargetContent") String courseTargetContent
    )
    {
        Target target=new Target();
        target.setCourseId(courseId);
        target.setCourseTargetId(courseTargetId);
        target.setCourseTargetShortname(courseTargetShortname);
        target.setBulumuTarget(bulumuTarget);
        target.setCourseTargetContent(courseTargetContent);
        return targetService.Lv_updateTarget(target);
    }

    @RequestMapping("/FindAllTarget")
    public String FindAllTarget()
    {
//        用gson来完成数据传输
        List<Target> list =targetService.Lv_selectAllTarget();
        Gson gson = new Gson();
        return gson.toJson(list);
    }

//    根据课程名称  检查课程目标
    @RequestMapping("/SearchCourseTarget")
    public String SearchCourseTarget(@Param("courseTargetShortname") String courseTargetShortname)
    {
        List<Target> list=targetService.Lv_searchCourseTarget(courseTargetShortname);
        Gson gson = new Gson();
        return gson.toJson(list);

    }
    @GetMapping("/findTargetContentById")
    public String findTargetContentById(@Param("courseId") Integer courseId){
        List<Target> byId= targetService.findTargetContentById(courseId);
        Gson gson = new Gson();
        return gson.toJson(byId);
    }

    @GetMapping("/findTargetAllById")
    public String findTargetAllById(Integer courseId){
        List<Target> byId= targetService.findTargetAllById(courseId);
        Gson gson = new Gson();
        return gson.toJson(byId);
    }

    @GetMapping("/findEvaluationWayById")
    public String findEvaluationWayById(Integer courseId){
        List<Target> byId= targetService.findEvaluationWayById(courseId);
        Gson gson = new Gson();
        return gson.toJson(byId);
    }

    @GetMapping("/findTargetContentByName")
    public String findTargetContentByName(@Param("courseName") String courseName){
        List<Target> byName = targetService.findTargetContentByName(courseName);
        Gson gson = new Gson();
        return gson.toJson(byName);
    }


    //更新各个课程目标的教学环节、评价方式、权值
    @RequestMapping("/updateTeacheWayById")
    public int updateTeacheWayById(Integer courseId, Integer courseTargetNum, String teacheWay, String evaluationWay, String evaluationValue){
        return targetService.updateTeacheWayById(courseId,courseTargetNum,teacheWay,evaluationWay,evaluationValue);
    }
    //更新期末考试要点
    @RequestMapping("/updateExamPointById")
    public int updateExamPointById(Integer courseId, Integer courseTargetNum, String examPoint){
        return targetService.updateExamPointById(courseId,courseTargetNum,examPoint);
    }


    @GetMapping("/findTargetContent")
    public String findTargetContent(@Param("courseId") Integer courseId){
        List<Target> byId= targetService.findTargetContent(courseId);
        Gson gson = new Gson();
        return gson.toJson(byId);
    }

    //更新教学环节详细内容
    @RequestMapping("/updateTargetContent")
    public int updateTargetContent(Integer courseId, String courseTarget, String courseTargetContent){
        return targetService.updateTargetContent(courseId,courseTarget,courseTargetContent);
    }

    @RequestMapping("/deleteTargetContent")
    public int deleteTargetContent(Integer courseId){
        return targetService.deleteTargetContent(courseId);
    }

    @GetMapping("/findEvaluationContent")
    public String findEvaluationContent(@Param("courseId") Integer courseId){
        List<Target> byId= targetService.findEvaluationContent(courseId);
        Gson gson = new Gson();
        return gson.toJson(byId);
    }

    //更新评价方式详细内容
    @RequestMapping("/updateEvaluationContent")
    public int updateEvaluationContent(Integer courseId, String courseTarget, String courseTargetContent){
        return targetService.updateEvaluationContent(courseId,courseTarget,courseTargetContent);
    }

    @RequestMapping("/deleteEvaluationContent")
    public int deleteEvaluationContent(Integer courseId){
        return targetService.deleteEvaluationContent(courseId);
    }


}
